#include<stdio.h>
#include <string.h>
#include <stdlib.h>
struct goods
{    	  	    	 
    int num;
    char type[20];
    char name[20];
    int  counts;
    struct goods*next;
}    	  	    	 *head;  //1
//函数声明
void creat();
void show();
void updateCount(int);
int pdelete(int num) ;
void Pfree(struct goods *head);
int main()         
{    	  	    	 
    int num;           
    creat();           //1
    show();            //1  
     // scanf("%d", &num);        
     printf("请输入要删除的商品编号：\n");
    scanf("%d", &num); //1
    if(pdelete(num)==1)                 //2
           show(); //1
    Pfree(head);                 //1
    return 0;
}    	  	    	 
//创建单链表保存联系人信息，并输出所有联系人信息
void  creat()                  //2
{    	  	    	 
    struct goods *q, *tail;              //1
    char flag = 'Y';
    head = (struct goods *)malloc(sizeof(struct goods));//1
    head->next = NULL;             //1
    tail = head;              
    while (flag == 'Y')   //1
    {    	  	    	 
        printf("请依次输入每个商品编号、类型、名称、数量：\n");
        q = (struct goods *)malloc(sizeof(struct goods));  //1
        q->next = NULL;                             
        scanf("%d %s %s %d", &q->num, &q->type, &q->name, &q->counts);//1
        tail->next = q;          //1
        tail = q;               
        printf("是否继续输入,按Y键继续输入，其他键就结束.\n");
        getchar();
        flag = getchar();    //1          
    }
}    	  	    	 
void show() //2
{    	  	    	 
    struct goods *out;        //1
    printf("输出所有商品信息为：编号 类型 名称 数量:\n");
    
    out = head->next;          //1
    while (out)
    {    	  	    	 
        printf("%d %s %s %d\n", out->num, out->type, out->name, out->counts);//1
        out = out->next;    //1
    }
}    	  	    	 
 
 int pdelete(int num) //2
{    	  	    	 
   struct goods *p, *q = NULL;
    q=head;     //1
    p=head->next;
    for ( ;p->num !=num; )//2
    {    	  	    	 
        q=p; //1
        p = p->next; //1
        if (p == NULL)//1
        {printf("不存在！");
        return 0;}
    }
    q->next=p->next; //1
    printf("商品删除成功！\n");
    free(p);  //1
    return 1;
}    	  	    	 
void Pfree(struct goods *head)//2
{    	  	    	 
   struct goods *p, *q; //1
    p = head;
    while (p->next != NULL) //1
    {    	  	    	 
        q = p->next;
        p->next = q->next;//1
        free(q);//1
    }
    free(p);
}